<template>
  <el-card class="page-container">
    <template #header>
      <div class="header">
        <span>
          <h2>申请休假</h2>
          <el-text>申请人: {{ empInfo?.empname }}</el-text>

        </span>
      </div>
    </template>
    <el-form :model="vocationModel"  label-width="auto" style="max-width: 600px">
      
      <el-form-item label="休假类型">
        <el-select v-model="vocationModel.vocationTypeId" placeholder="请选择休假类型">
          <el-option label="调休假" value="1" />
          <el-option label="年假" value="2" />
          <el-option label="事假" value="3" />
          <el-option label="产假" value="4" />
          <el-option label="病假" value="5" />
          <el-option label="产假" value="6" />
          <el-option label="护理假" value="7" />
          <el-option label="丧假" value="8" />
        </el-select>
      </el-form-item>
      <el-form-item label="休假开始时间">
        <el-col :span="11">
          <el-date-picker v-model="vocationModel.startTime" type="date" placeholder="选择日期" style="width: 100%" />
        </el-col>
        <el-col :span="2" class="text-center">
          <span class="text-gray-500">-</span>
        </el-col>
        <el-col :span="11">
          <el-time-picker v-model="vocationModel.startTime" placeholder="选择具体时间" style="width: 100%" />
        </el-col>
      </el-form-item>
      <el-form-item label="休假结束时间">
        <el-col :span="11">
          <el-date-picker v-model="vocationModel.endTime" type="date" placeholder="选择日期" style="width: 100%" />
        </el-col>
        <el-col :span="2" class="text-center">
          <span class="text-gray-500">-</span>
        </el-col>
        <el-col :span="11">
          <el-time-picker v-model="vocationModel.endTime" placeholder="选择具体时间" style="width: 100%" />
        </el-col>
      </el-form-item>

      <el-form-item label="休假原因">
        <el-input v-model="vocationModel.reason" type="textarea" />
      </el-form-item>
      <el-form-item style="">
        <el-button type="primary" @click="onSubmit">提交</el-button>
        <el-button @click="clearVocation()">重置</el-button>
      </el-form-item>
    </el-form>
  </el-card>

</template>
<script setup lang="ts">
import { ref } from 'vue'
import { requestVacation } from '../api'
import type { VocationReq } from '../model'
import { useEmpStore } from '../store/emp'
import { storeToRefs } from 'pinia'


const store = useEmpStore()
const { empInfo } = storeToRefs(store)
let vocationModel = ref<VocationReq>({
  empId : empInfo.value?.id ?? '',
  vocationTypeId : '',
  startTime : '',
  endTime : '',
  reason : ''
})

const onSubmit = () => {
  requestVacation(vocationModel.value).then(res => {
    if (res.code == 6000) {
      alert('休假申请提交成功！');
      // 可根据需求进行页面跳转或数据重置等操作
      clearVocation();
    } else {
      alert('休假申请提交失败：' + res.message);
    }
  }).catch(error => {
    console.error('提交休假申请时发生错误：', error);
    alert('提交休假申请时发生错误，请稍后重试。');
  });
}
const clearVocation = () => {
  vocationModel.value = {
    empId :'',
    vocationTypeId : '',
    startTime : '',
    endTime : '',
    reason : ''
  }
}



</script>


<style scoped></style>
